package com.neu.dao.impl;

import com.neu.dao.BaseDao;
import com.neu.dao.BillDao;

import java.util.List;
import java.util.Map;

public class BillDaoImpl extends BaseDao implements BillDao {

    @Override
    public List<Map<String, Object>> findAll() {
        List<Map<String,Object>> list=null;
        String sql="select bill_id,bill_money,bill_time,bill_explain,bill_member_id\n" +
                " from tbl_bill" +
                " where bill_status ='1'" ;
        list =super.executeQuery(sql);
        return list;
    }

    @Override
    public List<Map<String, Object>> findIncomeBill() {
        List<Map<String,Object>> list=null;
        String sql="select bill_id,bill_money,bill_time,bill_explain,bill_member_id\n" +
                " from tbl_bill" +
                " where bill_money >0 and bill_status ='1'" ;
        list =super.executeQuery(sql);
        return list;
    }

    @Override
    public List<Map<String, Object>> findConsumeBill() {
        List<Map<String,Object>> list=null;
        String sql="select bill_id,bill_money,bill_time,bill_explain,bill_member_id\n" +
                " from tbl_bill" +
                " where bill_money <0 and bill_status ='1'" ;
        list =super.executeQuery(sql);
        return list;
    }

    @Override
    public List<Map<String, Object>> findMemberBill(String id) {
        List<Map<String,Object>> list=null;
        String sql="select bill_id,bill_money,bill_time,bill_explain,bill_member_id\n" +
                " from tbl_bill" +
                " where bill_member_id=? and bill_status ='1'" ;
        list =super.executeQuery(sql);
        return list;
    }

    @Override
    public List<Map<String, Object>> findBillByDate(String date1, String date2) {
        List<Map<String,Object>> list=null;
        String sql="select bill_id,bill_money,bill_time,bill_explain,bill_member_id\n" +
                " from tbl_bill" +
                " where DATE_FORMAT(bill_time,'%Y-%m-%d') between ? and ?" +
                " and bill_status ='1'" ;
        list =super.executeQuery(sql,date1,date2);
        return list;
    }

    @Override
    public int insertBill(String money,  String explain,String id) {
        int row =0;
        String sql ="insert into tbl_bill(bill_money,bill_explain,bill_member_id)\n" +
                " values(?,?,?)";
        row=super.executeUpdate(sql,money,explain,id);
        return row;
    }

    @Override
    public int deleteBill(String id, String id2) {
        int row=0;
        String sql ="update tbl_bill set bill_status =0 where bill_id =? and bill_member_id =?";
        row=super.executeUpdate(sql,id,id2);
        return row;
    }

    @Override
    public int update(String money, String id,String id2) {
        int row=0;
        String sql ="update tbl_bill set bill_money =? where bill_id =? and bill_member_id =?";
        row=super.executeUpdate(sql,money,id,id2);
        return row;
    }

    @Override
    public List<Map<String, Object>> countIncome() {
        List<Map<String, Object>> list =null;
        String sql="select sum(bill_money) from tbl_bill  \n" +
                "\twhere bill_money>0";
        list = super.executeQuery(sql);
        return list;
    }

    @Override
    public List<Map<String, Object>> countConsume() {
        List<Map<String, Object>> list =null;
        String sql="select sum(bill_money) from tbl_bill  \n" +
                "\twhere bill_money<0";
        list = super.executeQuery(sql);
        return list;
    }


}
